package com.sfac.day03.modules.account.controller;

import com.github.pagehelper.PageInfo;
import com.sfac.day03.modules.account.entity.Role;
import com.sfac.day03.modules.account.service.RoleService;
import com.sfac.day03.modules.common.entity.ResultEntity;
import com.sfac.day03.modules.common.entity.SearchBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class RoleController {
    @Autowired
    private RoleService roleService;

    @PostMapping(value = "/role",consumes = "application/json")
    public ResultEntity<Role> insertRole(@RequestBody Role role){
     return roleService.insertRole(role);
    }
    @PutMapping(value = "/role",consumes = "application/json")
    public ResultEntity<Role> updateRole(@RequestBody Role role){
        return roleService.updateRole(role);

    }
    @DeleteMapping("/role/{id}")
    public ResultEntity<Object> deleteRoelById(@PathVariable int id){
        return roleService.deleteRoelById(id);
    }
    @GetMapping("/role/{id}")
    public Role getRoleById(@PathVariable int id){
        return roleService.getRoleById(id);

    }
    @GetMapping("/roles/{userId}")
    public List<Role> getRolesByUserId(@PathVariable int userId){
        return roleService.getRolesByUserId(userId);

    }
    @GetMapping("/roles")
    public List<Role> getRoles(){
        return roleService.getRoles();

    }
    @PostMapping(value = "/roles",consumes = "application/json")
    public PageInfo<Role> getRolesBySearchBean(@RequestBody SearchBean searchBean){
        return roleService.getRolesBySearchBean(searchBean);
    }
}
